package cn.mesmile.juc.dead;

/**
 * @author zb
 * @date 2021/8/16 22:53
 * @Description
 */
public class DeadLock {

    public static void main(String[] args) {
        Object a = new Object();
        Object b = new Object();
        new Thread(() -> {
            synchronized (a) {
                System.out.println(Thread.currentThread().getName()+ "获取到a,试图获取锁b");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b){
                    System.out.println("锁a中获取到锁b");
                }
            }
        },"A").start();

        new Thread(() -> {
            synchronized (b) {
                System.out.println(Thread.currentThread().getName()+ "获取到b,试图获取锁a");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a){
                    System.out.println("锁b中获取到锁a");
                }
            }
        },"B").start();
    }
}
